<template>
  <div class="poster-container">
    <img src="../assets/birdview-base.png">
    <div class="titleCard" @mouseenter="drawInk" @mouseleave="clearInk">
      <h1>新 院 <i class="fa fa-heart"></i> 心 愿</h1>
      <p>八里庄住区规划与住宅设计</p>
      <p>Sandhater&emsp;2019******&emsp;建9*</p>
      <span class="inkCircle" v-show="inkControl.showInk"></span>
    </div>
  </div>
</template>

<script>
export default {
  name:'Poster',
  data(){
    return{
      /*inkControl是一组用于控制染色效果的布尔量*/
      inkControl:{
        isIn: true,
        isOut: false,
        showInk: false
      }
    }
  },
  methods: {
    drawInk(e){
      if(this.inkControl.isIn){
        const card = document.querySelector('.titleCard')
        const inX = e.clientX - card.offsetLeft
        const inY = e.clientY - card.offsetTop

        this.inkControl.showInk = true
        const circle = document.querySelector('.inkCircle')
        circle.style.left = inX + 'px'
        circle.style.top = inY + 'px'
        
        circle.classList.remove('out')
        circle.classList.add('in')

        this.inkControl.isIn = false
        this.inkControl.isOut = true
      }
    },
    clearInk(e){
      if(this.inkControl.isOut){
        const card = document.querySelector('.titleCard')
        const outX = e.clientX - card.offsetLeft
        const outY = e.clientY - card.offsetTop

        const circle = document.querySelector('.inkCircle')
        circle.classList.remove('in')
        circle.classList.add('out')

        circle.style.left = outX + 'px'
        circle.style.top = outY + 'px'

        this.inkControl.isOut = false
        setTimeout(()=>{
          this.inkControl.showInk = false
          this.inkControl.isIn = true
        }, 500)
      }
    }
  },
  mounted(){
    this.$bus.$emit('flowUp')
  },
  beforeDestroy(){
    this.$bus.$emit('flowDown')
  },
}

</script>

<style scoped>
.poster-container{
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100vw;
  position: relative;
  overflow: hidden;
  position: absolute;
  background: var(--pale);
}

.poster-container > img{
  position: absolute;
  clip-path: polygon(0% 0%, 100% 0%, 100% 50%, 0% 50%);
  animation: fadeIn 2.5s;
}

.poster-container > .titleCard{
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: min(80vw, 80vh);
  height: min(50vw, 50vh);
  position: relative;
  overflow: hidden;
  z-index: 2;
  border-radius: 2rem;
  background: white;
  box-shadow: 0px 16px 48px rgba(50, 50, 50, 0.2);
  animation: flowIn 1s ease-out;
}

.titleCard > h1{
  color: var(--pink);
  font-size: min(8vw, 8vh);
  font-family: XiMaiTi;
  position: relative;
  transform: scaleX(120%);
  margin: 1.5rem 0;
  z-index: 1;
  transition: all 0.5s;
}

.titleCard > p{
  color: var(--blue);
  font-size: min(3vw, 3vh);
  font-family: XiMaiTi;
  position: relative;
  transform: scaleX(120%);
  margin: 0.5rem 0;
  z-index: 1;
  transition: all 0.5s;
}

.titleCard:hover{
  animation: swing 0.5s ease-in;
}

.titleCard:hover > h1, .titleCard:hover > p{
  color: white;
  transform: scaleX(132%) scaleY(110%);
  transition: all 0.5s;
}

.titleCard > .inkCircle.in{
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: var(--pink);
  transform: translate(-50%, -50%);
  animation: drawInk 0.5s ease-out forwards;
}

.titleCard > .inkCircle.out{
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: max(200vw, 200vh);
  height: max(200vw, 200vh);
  border-radius: 50%;
  background: var(--pink);
  transform: translate(-50%, -50%);
  animation: clearInk  0.5s ease-out forwards;
}

@keyframes drawInk {
  0%{
    width: 0;
    height: 0;
  }
  100%{
    width: 200vh;
    height: 200vh;
  }
}

@keyframes clearInk {
  0%{
    width: 200vh;
    height: 200vh;
  }
  100%{
    width: 0;
    height: 0;
  }
}

@keyframes flowIn{
  0%{
    opacity: 0;
    transform: translateY(2rem);
  }
  30%{
    opacity: 1;
  }
  40%{
    transform: translateY(-0.5rem);
  }
  100%{
    transform: translateY(0);
  }
}

@keyframes fadeIn{
  0%{
    opacity: 0;
  }
  100%{
    opacity: 1;
  }
}

@keyframes swing {
  10%{
    transform: rotate(2deg);
  }
  20%{
    transform: rotate(-2deg);
  }
  40%{
    transform: rotate(5deg);
  }
  60%{
    transform: rotate(-5deg);
  }
  80%{
    transform: rotate(2deg);
  }
  90%{
    transform: rotate(-2deg);
  }
}

</style>